package com.dqyy.order.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dqyy.order.entity.Dish;
import com.dqyy.order.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dish")
public class DishController {

    @Autowired
    private DishService dishService;

    @PostMapping
    public boolean addDish(@RequestBody Dish dish) {
        return dishService.save(dish);
    }

    @PutMapping("/{id}")
    public boolean updateDish(@PathVariable Long id, @RequestBody Dish dish) {
        dish.setId(id);
        return dishService.updateById(dish);
    }

    @DeleteMapping("/{id}")
    public boolean deleteDish(@PathVariable Long id) {
        return dishService.removeById(id);
    }

    @GetMapping("/{id}")
    public Dish getDish(@PathVariable Long id) {
        return dishService.getById(id);
    }

    @GetMapping("/list")
    public List<Dish> listDishes() {
        return dishService.list(new LambdaQueryWrapper<Dish>().eq(Dish::getStatus, 1));
    }
} 